package com.taptech.doufu.ui.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.taptech.doufu.R;
import com.taptech.doufu.bean.TipInfo;

/**
 * Created by lsy on 2015/8/21.
 */
public class CompetenceDialog extends Dialog implements View.OnClickListener {

    protected TipInfo tipInfo;
    private ImageView mGotoCompetenceBtn, mGiveupCompetenceBtn, mCloseCompetenceBtn;
    private TextView mComptenceTextView;

    public CompetenceDialog(Context context) {
        super(context);
    }

    public CompetenceDialog(Context context, int theme, TipInfo tipInfo) {
        super(context, theme);
        this.tipInfo = tipInfo;

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.competence_dialog_layout);
        initView();
    }

    private void initView() {
        mGotoCompetenceBtn = (ImageView) findViewById(R.id.goto_competent_btn);
        mGotoCompetenceBtn.setOnClickListener(this);
        mGiveupCompetenceBtn = (ImageView) findViewById(R.id.giveup_comptent_btn);
        mGiveupCompetenceBtn.setOnClickListener(this);
        mCloseCompetenceBtn = (ImageView) findViewById(R.id.close_comptent_btn);
        mCloseCompetenceBtn.setOnClickListener(this);
        mComptenceTextView = (TextView) findViewById(R.id.competence_msg_textview);
        if (tipInfo != null && tipInfo.getTipContent() != null) {
            mComptenceTextView.setText(tipInfo.getTipContent());
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.goto_competent_btn:
                dismissDialog();
                if (tipInfo.getTipListener()!=null) {
                    tipInfo.getTipListener().resultBack( 1 , tipInfo.getType() );
                }
                break;
            case R.id.giveup_comptent_btn:
                dismissDialog();
                if (tipInfo.getTipListener()!=null) {
                    tipInfo.getTipListener().resultBack( 2 , tipInfo.getType() );
                }
                break;
            case R.id.close_comptent_btn:
                dismissDialog();
                break;
        }
    }

    private void dismissDialog(){
        if (this.isShowing()){
            this.dismiss();
        }
    }
}
